const bar = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow',
    },
  },
  legend: {},
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true,
  },
  xAxis: [
    {
      type: 'category',
      data: [],
      axisLabel: {
        interval: 0,
        formatter: function (value: string) {
          let ret = '' //拼接加\n返回的类目项
          const maxLength = 5 //每项显示文字个数
          const valLength = value.length //X轴类目项的文字个数
          const rowN = Math.ceil(valLength / maxLength) //类目项需要换行的行数
          if (rowN > 1) {
            //如果类目项的文字大于5,
            for (let i = 0; i < rowN; i++) {
              let temp = '' //每次截取的字符串
              const start = i * maxLength //开始截取的位置
              const end = start + maxLength //结束截取的位置
              //这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
              temp = value.substring(start, end) + '\n'
              ret += temp //凭借最终的字符串
            }
            return ret
          } else {
            return value
          }
        },
      },
    },
  ],
  yAxis: [
    {
      type: 'value',
    },
  ],
  series: [
    {
      name: '曝光量',
      type: 'bar',
      stack: 'Ad',
      emphasis: {
        focus: 'series',
      },
      showBackground: true,
      data: [],
    },
    {
      name: '浏览量',
      type: 'bar',
      stack: 'Search Engine',
      emphasis: {
        focus: 'series',
      },
      showBackground: true,
      data: [],
    },
  ],
}

export { bar }
